import {Component, OnInit} from '@angular/core';
import {MatDialog} from '@angular/material';
import {NewProjectComponent} from '../new-project/new-project.component';
import {InviteComponent} from '../invite/invite.component';
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';

@Component({
  selector: 'app-project-list',
  templateUrl: './project-list.component.html',
  styleUrls: ['./project-list.component.scss']
  // providers: [MdDialog]
})
export class ProjectListComponent implements OnInit {
  projects: any = [
    {
      'name': 'MES管理系统',
      'des': 'MES管理系统描述',
      'coverImg': 'assets/img/covers/3.jpg'
    },
    {
      'name': '青春不朽客户管理系统',
      'des': '青春不朽客户管理系统描述',
      'coverImg': 'assets/img/covers/4.jpg'
    }
  ];

  constructor(
    private dialog: MatDialog // 依赖注入MdDialog用于打开对话框
  ) {
  }

  ngOnInit() {
    // this.projects = [
    //   {
    //     'name': 'MES管理系统',
    //     'des': 'MES管理系统描述',
    //     'coverImg': 'assets/img/covers/3.jpg'
    //   },
    //   {
    //     'name': '青春不朽客户管理系统',
    //     'des': '青春不朽客户管理系统描述',
    //     'coverImg': 'assets/img/covers/4.jpg'
    //   }
    // ];
  }

  openNewProjectDialog() {
    // 打开对话框
    const dialogRef = this.dialog.open(NewProjectComponent, {
      // width: '300px',
      // height: '300px',
      // position: {left: '10px', top: '10px'},
      data: {title: '新增项目'}
    });

    // 对话框关闭时接收对话框传过来的数据
    dialogRef.afterClosed().subscribe(result => console.log(result));

  }

  launchInviteDialog() {
    console.log('open dialog');
    const dialogRef = this.dialog.open(InviteComponent);
  }

  launchEditDialog(project) {
    const dialogRef = this.dialog.open(NewProjectComponent, {data: {title: '编辑项目', project: project}});
  }

  launchDelDialog() {
    const dialogRef = this.dialog.open(ConfirmDialogComponent, {data: {title: '删除项目', content: '是否要删除项目'}});
    dialogRef.afterClosed().subscribe(result => console.log(result));
  }
}
